home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
heaptrac
/
heaptrac.exe
/
TESTHT16.DPR
< prev
next >
Wrap
Text File
|
1996-04-10
|
2KB
|
78 lines
{
// HeapTrace
// Dynamic memory debugging for Borland Delphi.
//
// ⌐ 1996 Modelistica, Caracas. All rights reserved
// 73000.1064@compuserve.com
}
program TestHT16;
uses
HeapTrac,
WinTypes,
WinProcs,
Classes,
SysUtils;
{ shut down procedures must be declared far }
procedure ShowLogFile; far;
var
buf :array[0..255] of char;
begin
if FileExists(HeapTraceDefaultLogFileName) then
WinExec(StrPCopy(buf, 'NOTEPAD '+ HeapTraceDefaultLogFileName), sw_Show);
end;
const
LargeSize = $5FFF;
type
PTest = ^TTest;
TTest = array[1..LargeSize] of Byte;
TMyComponent = class(TComponent);
TMyList = class(TList);
TMyStringList = class(TStringList);
var
O1, O2 :TObject;
PT, PT2 :PTest;
P :Pointer;
begin
{ on shut down routines are called after
HeapTrace has been removed from the system }
HeapTraceOnShutDownDo(ShowLogFile);
{ the following two are valid but undocumented
in both Delphi 1.x and Delphi 2.0.
HeapTrace wil log them as errors if
htoIgnoreUndocumented is not set in HeapTraceOptions
HeapTrace32 will ignore them all the time}
GetMem(P, 0);
FreeMem(nil, 0);
O1 := TMyList.Create;
O2 := TMyComponent.Create(nil);
O2 := TMyStringList.Create;
O1.Free;
O1.Free; { ERROR: free an object twice }
New(PT); { ERROR: this object not freed }
New(PT);
GetMem(PT2, 4321);
FillChar(PT^, SizeOf(PT^)+1, #1); { ERROR: memory overrun }
Dispose(PT); { ERROR: object is invalid }
Dispose(PT); { ERROR: object freed twice }
FreeMem(PT2, 321); { ERROR: free incorrect size }
New(PT); { ERROR: this object not freed }
if (HeapTraceAvailableMemory >= SizeOf(TTest))
or (HeapTraceAvailableMemory = 0) then
SetHeapTraceAvailableMemory(SizeOf(TTest) div 2);
try
New(PT) { simulated out of memory condition }
except
end;
end.